package cn.zyx.org.service.impl;

import cn.zyx.basic.util.PageList;
import cn.zyx.org.domain.SystemDictionary;
import cn.zyx.org.domain.SystemDictionaryDetail;
import cn.zyx.org.mapper.SystemDictionaryMapper;
import cn.zyx.org.query.SystemDictionaryDetailQuery;
import cn.zyx.org.query.SystemDictionaryQuery;
import cn.zyx.org.service.ISystemDictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class SystemDictionaryServiceImpl implements ISystemDictionaryService {

    @Autowired
    private SystemDictionaryMapper systemDictionaryMapper;

    @Override
    @Transactional
    public void add(SystemDictionary systemDictionary) {
        systemDictionaryMapper.save(systemDictionary);
    }

    @Override
    @Transactional
    public void remove(Long id) {
        systemDictionaryMapper.delete(id);
    }

    @Override
    public List<SystemDictionary> getAll() {
        return systemDictionaryMapper.loadAll();
    }

    @Override
    public SystemDictionary getById(Long id) {
        return systemDictionaryMapper.loadById(id);
    }

    @Override
    @Transactional
    public void update(SystemDictionary systemDictionary) {
        systemDictionaryMapper.update(systemDictionary);
    }

    @Override
    public PageList<SystemDictionary> pageData(SystemDictionaryQuery systemDictionaryQuery) {
        // 查询总条数
        Integer total = systemDictionaryMapper.pageCount(systemDictionaryQuery);
        // 查询当前页数据
        List<SystemDictionary> rows = systemDictionaryMapper.pageData(systemDictionaryQuery);
        return new PageList<>(total,rows);
    }

    @Override
    public void batchDel(List<Long> ids) {
        systemDictionaryMapper.batchDel(ids);
    }

}
